
package com.mbbmap.app.servlet;

import javax.servlet.*;
import javax.servlet.http.*;

import com.mbbmap.util.Constants;

public final class CounterListener implements HttpSessionListener
    {
     private int count = 1;
     private ServletContext context = null;

     public synchronized void sessionCreated(HttpSessionEvent se)
         {
         count++;
         //log("sessionCreated("+se.getSession().getId()+") count="+count);
         se.getSession().setAttribute("eremitsessioncount",Integer.toString(count));
     }

     public synchronized void sessionDestroyed(HttpSessionEvent se)
         {
         count--;

         //log("sessionDestroyed("+se.getSession().getId()+") count="+count);
         se.getSession().setAttribute("eremitsessioncount",Integer.toString(Constants.CUR_WEB_CONN));
     }

     public int getCount()
         {
         return this.count;
     }

     public void addCount()
         {
         count++;
     }

     private void log(String message)
         {
         if (context != null)
         context.log("SessionListener: " + message);
         else
         System.out.println("SessionListener: " + message);
     }

}//close class CounterListener
